package designpatterns.singleton;

/**
 * @program: MyTank
 * @description:
 * @author: 王术平
 * @create: 2021-01-05 21:35
 **/
public class SingleTonByInteriorClass {
    private SingleTonByInteriorClass() {
    }
    public static SingleTonByInteriorClass getInstance() {
        return Instance.INSTANCE;
    }

    //可实现随用随加载，并且线程安全（与类加载相关，JVM为了保证Class对象是单例的，会在加载类的时候加锁）。
    static class Instance {
        private static final SingleTonByInteriorClass INSTANCE = new SingleTonByInteriorClass();
    }
}
